#delimit ;
set more off;

/*NOTE: For a Mac, file path names use a forward slash (/) but for 
PC's they require a backward slash (\). Make these changes below 
if necessary depending on your computer type. 
*/

*Dropbox paths by user;
if c(username)=="shayaksarkar" {;
	local path "/Users/shayaksarkar/Desktop/ReStat_Data_Publication";
};


/*TABLE 5*/;

cd `path';

local se cluster(date_auditor);

cap program drop zline;
program define zline;
	syntax varlist, line(string);

	** Unconditional mean;
		sum `varlist';
		mat t[`line',1]=r(mean);
		mat t[`line'+1,1]=r(sd);
	
	** Pre-regulation;
		sum `varlist' if post==0;
		mat t[`line',3]=r(mean);
		mat t[`line'+1,3]=r(sd);
	
		
	** Pre-regulation;
		sum `varlist' if post==1;
		mat t[`line',5]=r(mean);
		mat t[`line'+1,5]=r(sd);

	** Difference;
		reg `varlist' post, `se';
		mat t[`line',7]=_b[post];
		mat t[`line'+1,7]=_se[post];
		
	
end;
mat t=J(40,20,.);

use "`path'/dta/final_disclosure.dta", clear;
cap gen date=monthofaudit*100+dayofaudit;

keep if post!=.;

local i=1;
	zline lic, line(`i');

local i=`i'+3;

	** Location of Visit;
	zline agent_home, line(`i');
	local i=`i'+2;
	zline agent_office, line(`i');
	local i=`i'+2;
	zline auditor_home, line(`i');
	local i=`i'+2;
	zline auditor_office, line(`i');
	local i=`i'+2;
	zline other_venue, line(`i');
	local i=`i'+2;
	zline audit_duration, line(`i');
	local i=`i'+2;


local i=`i'+2;

	** Recommendations;
	
	zline onlywhole, line(`i');
	local i=`i'+2;
	zline onlyterm, line(`i');
	local i=`i'+2;
	zline onlyulip, line(`i');
	local i=`i'+2;
	zline anywhole, line(`i');
	local i=`i'+2;
	zline anyterm, line(`i');
	local i=`i'+2;
	zline anyulip, line(`i');
	local i=`i'+2;


	** SAMPLE SIZES;
	count;
	mat t[31,1]=r(N);
	
	count if post==0;
	mat t[31,3]=r(N);

	count if post==1;
	mat t[31,5]=r(N);

svmat t;
	local rfs 1,4,6,8,10,12,14,18,20,22,24,26,28;

	drop t8;
	gen t8="";
	replace t8="*" if abs(t7/t7[_n-1])>1.64 & inlist(_n,`rfs');
	replace t8="**" if abs(t7/t7[_n-1])>1.96 & inlist(_n,`rfs');
	replace t8="***" if abs(t7/t7[_n-1])>2.57 & inlist(_n,`rfs');
	
	aorder t*;
	
	outsheet t1-t20 if _n<35 using "`path'/out/table5.csv", comma replace;
